<template>
  <a-modal v-model="visible" title="底稿列表" width="60%">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="定性">
              <a-input placeholder="请输入" v-model="queryParam.dingxing"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="责任界定">
              <a-input placeholder="请输入" v-model="queryParam.zrjd"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="所属单位">
              <j-select-depart v-model="queryParam.comId" :trigger-change="true" customReturnField="id"
                               :multi="true"></j-select-depart>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
                <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">清除条件</a-button>
                </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
      <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
      selectedRowKeys.length }}</a>项&nbsp;&nbsp;
      <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
      <span slot="action" slot-scope="text, record">
        <a @click="handleCheck(record,'底稿列表-查看')">查看</a>
      </span>
    </a-table>
    <template slot="footer">
      <a-button key="back" style='padding-left:8px;padding-right:8px' @click='close(false)'>
        关闭
      </a-button>
      <a-popconfirm title='确定生成吗?' @confirm="() => create()">
        <a-button type="primary" key="save" style='padding-left:8px;padding-right:8px'>
          生成
        </a-button>
      </a-popconfirm>
    </template>
    <CheckAndEditModel ref="modalForm" @ok="modalFormOk"></CheckAndEditModel>
  </a-modal>
</template>

<script>
  import {httpAction, getAction} from '@/api/manage'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import CheckAndEditModel from './CheckAndEditModel'
  import columns from './columns'

  export default {
    name: "DrafView",
    mixins: [JeecgListMixin],
    components: {
      CheckAndEditModel
    },
    data() {
      return {
        /* table选中keys*/
        selectedRowKeys: [],
        /* table选中records*/
        selectionRows: [],
        queryParam: {},
        columns: columns(this),
        visible: false,
        dataSource: [],
        ipagination: {
          current: 1,
          pageSize: 10,
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          onChange: (pageNumber) => {
            this.onChange(pageNumber)
          },
          showQuickJumper: true,
          total: 0
        },
        url: {
          list: '/sjcg/sjWorkZtfaEveDigaoStandBook/getDgList',
          create: '/sjcg/sjWorkZtfaEveDigaoStandBook/shengDgDo'
        }
      }
    },
    created() {
      this.list()
    },
    watch: {},
    methods: {
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      },
      searchQuery() {
        this.list()
      },
      searchReset() {
        this.queryParam = {}
        this.list();
      },
      list() {
        getAction(this.url.list, {
          ...this.queryParam,
          pageSize: this.ipagination.pageSize,
          pageNo: this.ipagination.current
        }).then((res) => {
          if (res.success && res.result) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total;
          } else {
            this.ipagination.total = 0;
          }
        })
      },
      onChange(pageNumber) {
        this.ipagination.current = pageNumber
        this.list()
      },
      close() {
        this.onClearSelected()
        this.visible = false
      },
      create() {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
        } else {
          var ids = this.selectedRowKeys.toString()
          httpAction(this.url.create, {ids: ids}, 'post').then((res) => {
            if (res.success) {
              this.$message.success(res.message);
              this.$emit('ok');
              this.close()
            } else {
              this.$message.warning(res.message);
            }
          })
        }
      }
    }
  }
</script>

<style scoped>

</style>